package com.weizhizs.assistant.code.template.data;

import com.weizhizs.assistant.code.config.ParamConfig;
import com.weizhizs.assistant.code.helper.BeanHelper;
import com.weizhizs.assistant.code.helper.TableHelper;
import com.weizhizs.assistant.code.template.IDataLoador;
import com.weizhizs.assistant.code.vo.TableVO;
import com.weizhizs.assistant.utils.DateUtils;
import com.weizhizs.assistant.utils.StringUtils;

import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class IntfDocData implements IDataLoador {

    @Override
    public String getTemplateName(TableVO tableVO) {
        return ParamConfig.getInstance().getTemplatePath() + "/intf.txt.vm";
    }

    @Override
    public String getFileName(String tableName) {
        return "doc" + File.separator + tableName.toLowerCase() + "_intf.txt";
    }

    @Override
    public String getFileOutPath() {
        return "";
    }

    @Override
    public Map<String, Object> getDataMap(TableVO tableVO) {
        String tableName = tableVO.getTableName();

        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        map.put("tableComment", tableVO.readTableComment());
        map.put("tableCommentFull", tableVO.getTableComment());
        map.put("authorName", ParamConfig.getInstance().getAuthorName());
        map.put("version", ParamConfig.getInstance().getVersion());
        map.put("currentDate", DateUtils.nowDateString());

        map.put("pk", tableVO.getPk());
        map.put("allColumns", tableVO.getAllColumns());

        map.put("entityLocalFields", Arrays.asList(ParamConfig.getInstance().getEntityLocalFields()));

        String dtoInstanceName = StringUtils.firstToLowerCase(TableHelper.tableNameToClassName(tableName));
        String requestPath = TableHelper.getRequestPath(dtoInstanceName);
        String permPath = requestPath.replace("/", ":");

        map.put("dtoInstanceName", dtoInstanceName);
        map.put("permPath", permPath);
        map.put("requestPath", requestPath);
        map.put("urlRoot", ParamConfig.getInstance().getAppUrlRoot());

        return map;
    }

}
